﻿#define DEBUG
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSP.Common.Web.Providers;
using CSP.Common.Web.Factories;


namespace CSP.Common.Web
{
    public class CSPMyHome : CSPPageBase
    {


        private UserProviderFactory _userProviderFactory;

        public UserProviderFactory UserProviderFactory
        {
            get { return _userProviderFactory; }
        }

        private UserProvider _userProvider;

        public UserProvider UserProvider
        {
            get { return _userProvider; }
        }

        protected override void OnInit(EventArgs e)
        {
            //权宜之计 暂时 持久化用户为admin,用户登陆体系完成后，删除此代码
#if (DEBUG)
            //Session["userName"] = "admin";
#else 
     
#endif
            base.OnInit(e);
            _userProviderFactory = UserProviderFactory.GetInstance(this);
            _userProvider = _userProviderFactory.UserProvider;
            //权限验证
            PermissionValidation();
        }

        /// <summary>
        /// 权限验证
        /// </summary>
        private void PermissionValidation()
        {
            if (string.IsNullOrEmpty(UserProvider.UserName))
            {
                //ToDo 跳转登陆页面
                Response.Redirect("/UCenter/Login.aspx?urlback=" + Server.UrlEncode(Request.Url.OriginalString));
            }
        }
    }
}
